#!/bin/bash

[ $# -eq 0 ] && { echo "Usage: $0 WORDSFILE"; exit 1; }

WORDSFILE=$1

ls  | grep Test- > dir-file.txt

cat dir-file.txt | while read TESTDIR
do
	cat $WORDSFILE | while read WORD
	do
		echo $TESTDIR
		grep 'instance id=' $TESTDIR/$WORD/LEXELT-test.xml |  sed 's/.*id="\([0-9]*\)".*/\1/' > $TESTDIR/$WORD/ids.txt		
	done	
done 

cat $WORDSFILE | while read WORD
do
	paste `ls Test-en*/$WORD/ids.txt` > FINAL-RESULTS/$WORD-instances.txt
done